package com.vcredit.creditcat.service;
import com.vcredit.creditcat.model.CatfoodTypeName;
import com.vcredit.creditcat.persistence.base.CatfoodTypeNameMapper;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cache.annotation.CacheEvict;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.stereotype.Service;
/**
 * 
 **/
@Service
public class CatfoodTypeNameService {
	@Autowired
    private CatfoodTypeNameMapper mapper;
    
	@CacheEvict(key = "'CatfoodTypeName'", value = "default")
    public void insert(CatfoodTypeName obj){
    	mapper.insert(obj);
    }
    
    @CacheEvict(key = "'CatfoodTypeName'", value = "default")
    public void update(CatfoodTypeName obj){
    	mapper.update(obj);
    }
    
    public List<CatfoodTypeName> findAll(){
		return mapper.findAll();
	}
    
    @Cacheable(key = "'CatfoodTypeName'", value = "default")
    public Map<Long,CatfoodTypeName> findForMap(){
		List<CatfoodTypeName> findAll = this.findAll();
		Map<Long,CatfoodTypeName> result = new HashMap<Long,CatfoodTypeName>();
		for(CatfoodTypeName catfoodTypeName : findAll) {
			result.put(catfoodTypeName.getId(), catfoodTypeName);
		}
		return result;
	}
	
	private List<CatfoodTypeName> find(CatfoodTypeName obj){
		return mapper.find(obj);
	}
		
	public CatfoodTypeName findById(Long  typeId){
		return mapper.findById(typeId);
	}		
}